<?php
namespace app\admin\controller;
use think\Controller;
//登录控制器

class Index extends Controller
{
    //重复登录过滤
    public function initialize()
    {
        if (session('?admin.id')) {
            $this->redirect('admin/home/index');
            
        }
    }

    	//后台登录
        public function login()
        {
            if (request()->isAjax()) {
                if(!captcha_check(input('post.code'))){
                    $this->error('验证码错误');
                   };
                $data=[
                    'username'=>input('post.username'),
                    'password'=>input('post.password')
                    
                ];
                
               
                $result=model('Admin')->login($data);
                 if ($result == 1) {
                    $this->success('登录成功！', 'admin/home/index');
                }else {
                    $this->error($result);
                }
                
            }
            return view();
        }

       








}